package cn.azzhu.springdemo.controller;

import cn.azzhu.springdemo.bean.User;
import cn.azzhu.springdemo.config.ConfigInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author azzhu
 * @create 2020-08-22 09:19:02
 */
//@RestController //@Controller + @ResponseBody
@Controller
public class HelloController {

/*    @Value("${boot.name}")
    private String username;

    @Value("${boot.pwd}")
    private String passwd;*/

    @Autowired
    private ConfigInfo configInfo;

    @GetMapping("/hello")
    public @ResponseBody  String hello(@RequestParam(value = "name", defaultValue = "World",required = false) String name) {
        return String.format("Hello %s!", name);
    }

    @GetMapping("list")
    public String getAll(Map<String,Object> map) {
        map.put("msg","helloThymeleaf");
        map.put("msg2","发送到发大水发");
        map.put("user",new User(1011,"孙悟空"));
        return "index";
    }

    @GetMapping("del/{id}")
    public String del(@PathVariable("id") Integer id) {
        System.out.println("====>id"+id);
        return "index";
    }

    @GetMapping("list2")
    public String list(Map<String,Object> map) {
        List<User> users = new ArrayList<>();
        users.add(new User(1011,"孙悟空"));
        users.add(new User(1012,"孙悟空2"));
        users.add(new User(1013,"孙悟空3"));

       // System.out.println("====>"+username+","+passwd);
        System.out.println(configInfo);
        map.put("users",users);
        return "index";
    }
}
